#include "splitTool.h"

SplitTool::SplitTool()
:jieba(DICT_PATH,HMM_PATH,USER_DICT_PATH,IDF_PATH,STOP_WORD_PATH)
{
    getStopWords();
}

void SplitTool::getStopWords(){
    ifstream ifs("cppjieba/dict/stop_words.utf8");
    string word;
    while(ifs>>word){
        _stopWords.push_back(word);
    }
}

void SplitTool::removeStopWords(){
    auto iter=_result.begin();
    while(iter!=_result.end()){
        if(find(_stopWords.begin(),_stopWords.end(),*iter)!=_stopWords.end()){
             _result.erase(iter);
        }
        else{
            ++iter;
        }
    }
}

vector<string> SplitTool::cut(string &s)
{
    jieba.Cut(s,_result,true);
    removeStopWords();
    return _result;
}

void SplitTool::print() const{
    for(auto elem:_result){
        cout<<elem<<" ";
    }
}